package com.hackerrank.challenges.bytelandiantours;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Solution {
	private static void buildRoads(Map<Integer, Set<Integer>> map) {
		Map<Integer, Set<Integer>> map2 = new HashMap<Integer, Set<Integer>>();
		for(int s : map.keySet()) {
			for(int m : map.get(s)) {
				for(int t : map.get(m))
					if(t != s)
						add(map2, s, t);
			}
		}
		for(int key : map2.keySet())
			map.get(key).addAll(map2.get(key));
	}
	private static void add(Map<Integer, Set<Integer>> map, int n1, int n2) {
		Set<Integer> set = map.get(n1);
		if(set == null) {
			set = new HashSet<Integer>();
			map.put(n1, set);
		}
		set.add(n2);
	}
	private static int numWays(Map<Integer, Set<Integer>> map, int s, boolean v[], int nv) {
		if(nv == v.length)
			return map.get(s).contains(0) ? 1 : 0;
		int nw = 0;
		for(int n : map.get(s)) {
			if(!v[n]) {
				v[n] = true;
				nw += numWays(map, n, v, nv + 1);
				v[n] = false;
			}
		}
		return nw;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for(int t = 0; t < T; t++) {
			int N = in.nextInt();
			Map<Integer, Set<Integer>> map = new HashMap<Integer, Set<Integer>>();
			for(int i = 1; i < N; i++) {
				int n1 = in.nextInt(), n2 = in.nextInt();
				add(map, n1, n2);
				add(map, n2, n1);
			}
			buildRoads(map);
			boolean v[] = new boolean[N];
			v[0] = true;
			System.out.println(numWays(map, 0, v, 1));
		}
	}
}
